package cn.mesmile.interview.demo;

/**
 * @author zb
 * @date 2021/11/7 15:23
 * @Description
 */
public class Demo1 {

    public static void main(String[] args) {
        // 2 * 2 的 3 次方
        System.out.println(2<<3);
        // 8 * 2 的 3 次方
        System.out.println(8<<3);

        swap(2,6);
        swap2(2,6);

        System.out.println("test1() = " + test1());
        System.out.println("test2() = " + test2());
    }

    public static void swap(int a, int b){
        System.out.printf("a=%d, b=%d",a,b);
        a = a + b;
        b = a - b ;
        a = a - b;
        System.out.printf("\na=%d, b=%d",a,b);
    }

    public static void swap2(int a, int b){
        System.out.println();
        // b
        System.out.println(a^a^b);
        System.out.printf("\na=%d, b=%d",a,b);
        a = a^b;
        b = a^b ;
        a = a^b;
        System.out.printf("\na=%d, b=%d",a,b);
    }

    public static int test1() {
        int a = 1;
        try {
            System.out.println(a / 0);
            a = 2;
        } catch (ArithmeticException e) {
            a = 3;
            return a;
        } finally {
            a = 4;
        }
        return a;
    }

    public static int test2() {
        int a = 1;
        try {
            System.out.println(a / 0);
            a = 2;
        } catch (ArithmeticException e) {
            a = 3;
            return a;
        } finally {
            a = 4;
            return a;
        }
    }
}
